package io.github.dunwu.javacore.jdk8.nashorn;

import io.github.dunwu.javacore.jdk8.lambda.Person;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.NashornScriptEngine;

/**
 * @author Benjamin Winterberg
 */
public class Nashorn8 {

	public static void main(String[] args) throws ScriptException, NoSuchMethodException {
		NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn");
		engine.eval("load('res/nashorn8.js')");

		engine.invokeFunction("evaluate1"); // [object global]
		engine.invokeFunction("evaluate2"); // [object Object]
		engine.invokeFunction("evaluate3", "Foobar"); // Foobar
		engine.invokeFunction("evaluate3", new Person("John", "Doe")); // [object global]
		// <- ???????
	}

}
